#include"../../include/SplitEnglish.h"
#include<sstream>
using namespace std;

SplitEnglish::SplitEnglish(Configuration &conf)
:_conf(conf)
{

}

SplitEnglish::~SplitEnglish()
{

}

vector<string> SplitEnglish::cut(const string &data)
{
    set<string> unDict = _conf.getStopWordList();
    vector<string> res;
    stringstream ss;
    ss<<data;
    while(ss)
    {
        string word;
        ss>>word;
        for(auto it = word.begin();it!=word.end();)
        {
            if(!isWord(*it))
            {
                word.erase(it);
            }
            else{
                isLower(*it);
                ++it;
            }
        }
        if(word.size() == 0)continue;
        if(unDict.find(word)!=unDict.end())
        {
            //重复
            continue;
        }
        res.push_back(word);
    }
    return res;   
}


bool SplitEnglish::isWord(char ch)
{
    return (ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z');
}

void SplitEnglish::isLower(char &ch)
{
    if(ch>='A'&&ch<='Z')
        ch+=32;
}